package top.tenebrous.yzl.utils;

import org.apache.commons.lang3.StringUtils;

public class CommonUtils {

    private final static String SEPARATION = ":";

    private final static String REDIS_KEY_PREFIX = "IMA-PUBLIC-HEALTH" + SEPARATION;

    public static String generationRedisKey(String areaCode, String other){
        if (StringUtils.isEmpty(areaCode)) {
            areaCode = "";
        }
        if (StringUtils.isEmpty(other)) {
            other = "";
        }
        return REDIS_KEY_PREFIX + other + SEPARATION + areaCode;
    }

    public static String generationRedisKey(String areaCode, Long offsetStart, Long offsetEnd){
        String offsetStartStr = String.valueOf(offsetStart);
        String offsetEndStr = String.valueOf(offsetEnd);
        if (StringUtils.isEmpty(areaCode)) {
            areaCode = "";
        }
        if (offsetStart == null) {
            offsetStartStr = "";
        }
        if (offsetEnd == null) {
            offsetEndStr = "";
        }
        return REDIS_KEY_PREFIX + areaCode + SEPARATION + offsetStartStr + SEPARATION + offsetEndStr;
    }

    public static void main(String[] args) {
        String s = generationRedisKey("340122199411", 0L, 99L);
        String s1 = generationRedisKey("340122199411", "GET_LOCK");
        String s2 = generationRedisKey("340122199411", "RESIZE_LOCK");
        System.out.println(s);
        System.out.println(s1);
        System.out.println(s2);
    }
}
